/**
 * 管理初始化
 */
var ClmResource = {
    id: "ClmResourceTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ClmResource.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '附件id', field: 'resourceId', visible: true, align: 'center', valign: 'middle'},
            {title: '站点id', field: 'siteId', visible: true, align: 'center', valign: 'middle'},
            {title: '所属老师的id', field: 'teacherId', visible: true, align: 'center', valign: 'middle'},
            {title: '老师的姓名', field: 'teacherName', visible: true, align: 'center', valign: 'middle'},
            {title: '附件名称', field: 'fileName', visible: true, align: 'center', valign: 'middle'},
            {title: '附件上传地址', field: 'fileUrl', visible: true, align: 'center', valign: 'middle'},
            {title: '附件类型，doc代表文档，video代表视频', field: 'fileType', visible: true, align: 'center', valign: 'middle'},
            {title: '附件大小', field: 'fileSize', visible: true, align: 'center', valign: 'middle'},
            {title: '后缀', field: 'fileExt', visible: true, align: 'center', valign: 'middle'},
            {title: '视频时长', field: 'videoTime', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createDate', visible: true, align: 'center', valign: 'middle'},
            {title: '创建者', field: 'createUserId', visible: true, align: 'center', valign: 'middle'},
            {title: '是否删除,true(1)删除，false(0)正常', field: 'beDeleted', visible: true, align: 'center', valign: 'middle'},
            {title: '审核内容', field: 'checkComment', visible: true, align: 'center', valign: 'middle'},
            {title: '审核者id', field: 'checkUserId', visible: true, align: 'center', valign: 'middle'},
            {title: '审核者姓名', field: 'checkUserName', visible: true, align: 'center', valign: 'middle'},
            {title: '审核时间', field: 'checkDate', visible: true, align: 'center', valign: 'middle'},
            {title: '资源截图地址', field: 'logoUrl', visible: true, align: 'center', valign: 'middle'},
            {title: '学段，primary_school--小学，middle_school---初中，high_school---高中', field: 'stages', visible: true, align: 'center', valign: 'middle'},
            {title: '科目id', field: 'subjectId', visible: true, align: 'center', valign: 'middle'},
            {title: '科目名称', field: 'subjectName', visible: true, align: 'center', valign: 'middle'},
            {title: '作品简介', field: 'description', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
ClmResource.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        ClmResource.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
ClmResource.openAddClmResource = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/clmResource/clmResource_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
ClmResource.openClmResourceDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/clmResource/clmResource_update/' + ClmResource.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
ClmResource.delete = function () {
    if (this.check()) {
    	var operation = function(){
	        var ajax = new $ax(Feng.ctxPath + "/clmResource/delete", function (data) {
	            Feng.success("删除成功!");
	            ClmResource.table.refresh();
	        }, function (data) {
	            Feng.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("clmResourceId",this.seItem.id);
	        ajax.start();
    	};
    	Feng.confirm("是否删除?",operation);
    }
};

/**
 * 查询列表
 */
ClmResource.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    ClmResource.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = ClmResource.initColumn();
    var table = new BSTable(ClmResource.id, "/clmResource/list", defaultColunms);
    table.setPaginationType("client");
    ClmResource.table = table.init();
});
